axios.defaults.baseURL = "http://www.liulongbin.top:3007"

// 创建请求拦截器
axios.interceptors.request.use(
  function (config) {
    if (config.url.indexOf("my") != -1) {
      // config.headers = {
      //   Authorization: localStorage.getItem("userTokenH1"),
      // }
      // 上述写法错误
      config.headers["Authorization"] = localStorage.getItem("userTokenH1")
    }
    return config
  },
  function (error) {
    return Promise.reject(error)
  }
)

// 创建响应拦截器
axios.interceptors.response.use(
  function (response) {
    if (response.data.message == "身份认证失败！") {
      // 删除本地token
      localStorage.removeItem("userTokenH1")
      location.href = "/login.html"
    }
    return response
  },
  function (error) {
    return Promise.reject(error)
  }
)
